#include <cstdio>
#include <cstring>

int main(int argc, char const *argv[]) {
    int a, b;
    char input_str[40];
    while (scanf("%d%s%d", &a, input_str, &b) != EOF) {
        int decimal_a = 0, length = strlen(input_str), weight = 1; //initial weight = a^0 = 1
        for (int i = length - 1; i >= 0; i--) {
            int temp_num;
            if (input_str[i] >= '0' && input_str[i] <= '9')
                temp_num = input_str[i] - '0';
            else if (input_str[i] >= 'a' && input_str[i] <= 'z')
                temp_num = input_str[i] - 'a' + 10;
            else
                temp_num = input_str[i] - 'A' + 10;
            decimal_a += temp_num * weight; // weight = a^0、a^1、a^2...a^（length-1）
            weight *= a;
        }
        char result[40], size = 0;
        do {
            int temp_num = decimal_a % b;
            result[size++] = (temp_num < 10) ? temp_num + '0' : temp_num - 10 + 'A';
            decimal_a /= b;
        } while (decimal_a != 0);
        for (int i = size - 1; i >= 0; i--)
            printf("%c", result[i]);
        printf("\n");
    }
    return 0;
}